/**
 * Created by Administrator on 2016/8/18.
 */
app.controller('registerCtrl',function ($scope,$http) {
    $scope.userdata={};
    $scope.message="";
    $scope.registerSubmit=function () {
        if($scope.userForm.$valid){
            console.log($scope.userdata);
            $http({
                url:"/register",
                data:$scope.userdata,
                method:"post"
            }).success(function(data, status, headers, config){
                if(data.data=="no"){
                    $scope.message="该用户名已被注册";
                }else{
                    window.location.assign('/login');
                }
            }).error(function(data, status, headers, config){
                alert("注册失败");
            })
        }
    };

});
app.controller('loginCtrl',function ($scope,$http) {
    $scope.userdata={};
    $scope.message="";
    $scope.loginSubmit=function () {
        if($scope.userForm.$valid){
            console.log($scope.userdata);
            $http({
                url:"/login",
                data:$scope.userdata,
                method:"post"
            }).success(function(data, status, headers, config){
                if (data == "fail") {
                    $scope.message="用户名或密码错误";
                } else {
                    window.location.assign('/operator');
                }
            }).error(function(data, status, headers, config){
                alert("登录失败");
            })
        }
    };

});
app.directive('compare',function () {
    var o={};
    o.strict="AE";
    o.scope={
        orgText:"=compare"
    };
    o.require='ngModel';
    o.link=function (sco,ele,att,con) {
        con.$validators.compare=function (v) {
            return v==sco.orgText;
        };
        sco.$watch('orgText',function () {
            con.$validate();
        });
    };
    return o;
});